package com.shine.ws.client;

import com.shine.ws.client.util.ClientLoginInterceptor;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

/**
 * @Description: 基于代理实现WebService客户端调用
 * @CreateTime: 2023/7/17 10:34
 * @Version:
 * @Since: 1.8
 * @Author: Forward Seen
 */
public class CXFClientDynamic {
    public static void main(String[] args) throws Exception {
        String address = "http://127.0.0.1:8080/services/MessageService?wsdl";
        JaxWsDynamicClientFactory jaxWsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client = jaxWsDynamicClientFactory.createClient(address);
        client.getOutInterceptors().add(new ClientLoginInterceptor("forward","password"));
        String message = "这是一条来自客户端的消息";
        Object[] result = client.invoke("echo", message);//业务调用
        System.out.println(result[0]);
    }
}